package com.taobao.daxue.ui
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.HTTPStatusEvent;
	import flash.events.IOErrorEvent;
	import flash.events.MouseEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	
	import org.aswing.JButton;
	import org.aswing.JLoadPane;
	import org.aswing.JPanel;
	import org.aswing.JScrollPane;
	import org.aswing.JViewport;
	import org.aswing.LayoutManager;
	import org.aswing.SoftBoxLayout;
	
	public class PptControlPanel extends JPanel
	{
		private var m_scrollPane:JScrollPane;
		private var m_loadPane:JLoadPane;
		private var m_viewPort:JViewport;
		private var m_mcPpt:MovieClip;
		
		private var m_pnlControlBtns:JPanel;
		private var m_btnNext:JButton;
		private var m_btnPrevious:JButton;
		private var m_btnMagnify:JButton;
		private var m_pptUrl:String;
		
		
		public function PptControlPanel(layout:LayoutManager=null, pptUrl:String)
		{
			super(layout);
			this.m_pptUrl=pptUrl;
			createUI();
		}
		
		private function createUI():void {
			// set layout
			setLayout(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 2, SoftBoxLayout.LEFT));
			
			// load the ppt swf
			m_loadPane = new JLoadPane();
			m_loadPane.load(new URLRequest(m_pptUrl));
			addLoadEventListener();
			
			// create view port
			m_viewPort = new JViewport(m_loadPane);
			m_scrollPane = new JScrollPane(m_viewPort);
			append(m_scrollPane);
			
			// create control button panel
			m_pnlControlBtns = new JPanel(SoftBoxLayout.X_AXIS, 2, SoftBoxLayout.LEFT);
			append(m_pnlControlBtns);
			
			m_btnPrevious = new JButton("上一页");
			m_pnlControlBtns.append(m_btnPrevious);
			m_btnPrevious.addEventListener(MouseEvent.CLICK, onBtnPreviousClick);
			
			m_btnNext = new JButton("下一页");
			m_pnlControlBtns.append(m_btnNext);
			m_btnNext.addEventListener(MouseEvent.CLICK, onBtnNextClick);
			
			m_btnMagnify = new JButton("放大");
			m_pnlControlBtns.append(m_btnMagnify);
			m_btnMagnify.addEventListener(MouseEvent.CLICK, onBtnMagnifyClick);
			
		}
		
		private function onBtnPreviousClick(e:MouseEvent):void {
			// TODO: need implements	
		}
		
		private function onBtnNextClick(e:MouseEvent):void {
			// TODO：need implements	
		}
		
		private function onBtnMagnifyClick(e:MouseEvent):void {
			// TODO: need implements
		}
		
		
		private function addLoadEventListener():void {
			m_loadPane.addEventListener(Event.COMPLETE, onLoadComplete);
			m_loadPane.addEventListener(HTTPStatusEvent.HTTP_STATUS, onLoadHttpStatus);
			m_loadPane.addEventListener(IOErrorEvent.IO_ERROR, onLoadIoError);
			m_loadPane.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
		}
		
		private function onLoadComplete(e:Event):void {
			m_loadPane = e.target as JLoadPane;
			m_mcPpt = m_loadPane.loaderInfo.loader.content as MovieClip;
		}
		
		private function onLoadHttpStatus(e:HTTPStatusEvent):void {
			trace("onLoadHttpStatus, status="+e.status);
		}
		
		private function onLoadIOError(e:IOErrorEvent):void {
			trace("onLoadIOError, error="+e.toString());
		}
		
		private function onLoadProgress(e:ProgressEvent):void {
			trace("onLoadProgress, bytesRecved:"+e.bytesLoaded
				+", progress="+int(e.bytesLoaded*100/e.bytesTotal)+"%");
		}
			
	}
}